<#assign ctx=request.contextPath />
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>添加</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="${ctx}/static/layuiadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="${ctx}/static/layuiadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="${ctx}/static/layuiadmin/style/admin.css" media="all">
</head>
<body>

<div class="layui-form" lay-filter="layuiadmin-form-friend" id="layuiadmin-form-friend" style="padding: 20px 0 0 0;">

    <div class="layui-form-item">
    <label class="layui-form-label">用户电话</label>
    <div class="layui-input-block" name="single_select">

        <div class="layui-form-select" style="width: 221.2px">

            <div class="layui-select-title">
                <input type="text" class="layui-input" placeholder="用户电话"
                       name="userId" autocomplete="off" id="userId"  lay-verify="required">

                <i class="layui-edge"></i>
            </div>
            <dl name="select_show" class="layui-anim layui-anim-upbit">
                <dd lay-value="" class="layui-select-tips" style="text-align: center">
                    <i class="layui-icon layui-icon-loading layui-icon layui-anim layui-anim-rotate layui-anim-loop"></i>
                </dd>
            </dl>
        </div>
    </div>
    </div>

    <div class="layui-form-item">
    <div class="layui-inline">
        <label class="layui-form-label">变动类型</label>

        <div class="layui-input-block">
            <select name="type" lay-verify="" id="type" lay-verify="required" class="layui-input" >
                <!--                     <option value="0">用户</option> -->
                <option value="1">加</option>
                <option value="2">减</option>
            </select>
            <!--<input type="text" name="typeName" placeholder="请输入" autocomplete="off" class="layui-input">-->
        </div>
    </div>
</div>


    <div class="layui-form-item">
        <label class="layui-form-label">变动积分</label>
        <div class="layui-input-inline" style="width: 221.2px">

            <input type="text"
                   onkeyup='this.value=this.value.replace(/[^0-9]*$/,"")' onblur='this.value=this.value.replace(/^[0]+[0-9]*$/gi,"")' placeholder="请输入要变动的数值"

                   name="point"  lay-verify="number" placeholder="" autocomplete="off" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">积分消费/获得途径</label>

            <div class="layui-input-block">
                <select name="subType" lay-verify="" id="subType" lay-verify="required" class="layui-input" >
                    <option value="7">管理员操作</option>
                </select>

            </div>
        </div>
    </div>


    <!--</div>-->
    <!--<label class="layui-form-label">好友电话</label>-->
    <!--<div class="layui-input-block" name="single_select_friend">-->

        <!--<div class="layui-form-select" style="width: 200px">-->

            <!--<div class="layui-select-title">-->

                <!--<input type="text" class="layui-input" placeholder="好友电话"-->
                       <!--name="friendId" autocomplete="off" id="friendId">-->
                <!--<i class="layui-edge"></i>-->
            <!--</div>-->
            <!--<dl name="select_show" class="layui-anim layui-anim-upbit">-->
                <!--<dd lay-value="" class="layui-select-tips" style="text-align: center">-->
                    <!--<i class="layui-icon layui-icon-loading layui-icon layui-anim layui-anim-rotate layui-anim-loop"></i>-->
                <!--</dd>-->
            <!--</dl>-->
        <!--</div>-->
    <!--</div>-->




    <div class="layui-form-item layui-hide">
        <!--<input type="button" lay-submit lay-filter="LAY-friendForm-front-submit" id="LAY-friendForm-front-submit" value="确认">-->
        <input type="button" lay-submit lay-filter="LAY-user-front-submit" id="LAY-user-front-submit" value="确认">
    </div>
</div>

<script src="${ctx}/static/layuiadmin/layui/layui.js"></script>


<script>
    var ctx = "${ctx}";
    layui.config({
        base: ctx + '/static/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'friends', 'table'], function(){
        var $ = layui.$
            ,form = layui.form
            ,table = layui.table;

        function select_adaption(select_input) {
            var div_width = select_input.prev().outerWidth(true)
            select_input.css('padding-left', (parseInt(div_width) + 6) + 'px')
            select_input.val('')
        }

        //select模糊搜索
        function vagueselect(obj, type) {
            if (type=='single'){
                var select_input = obj.find('[name="userId"]')
            }
            // if (type=='select_friend') {
            //     var select_input = obj.find('[name="friendId"]')
            // }
            var select_show = obj.find('[name="select_show"]')
            // console.log(select_input);
            // console.log(type);
            function getdataList() {
                var parms = new Object();
                // console.log(select_input.val())
                parms["keyword"] = select_input.val();
                parms["csrfmiddlewaretoken"] = $("[name = 'csrfmiddlewaretoken']").val()
                if (parms["keyword"]=""){

                }
                else {
                    $.ajax({
                        cache: true,
                        type: "POST",
                        url: ctx +"/user/findListm/",
                        data: {userId:select_input.val()},
                        async: false,
                        success: function (data) {
                            // console.log(data);
                            var html;
                            if (data.code==1){
                                select_show.children().first().hide().nextAll().remove()
                                for (var i = 0; i < data.reObj.length; i++) {
                                    html = '<dd lay-value="' +  data.reObj[i].nickname+ '" class="">' + data.reObj[i].phone + '</dd>';
                                    select_show.append(html)
                                }
                            }
                            else{
                                select_show.children().first().hide().nextAll().remove()
                            }
                        },
                        error: function (request) {
                            layer.msg("请输入数字id！", {icon: 2});
                        }
                    });
                }

            }

            //输入框聚焦事件
            select_input.focus(function () {
                obj.find('.layui-form-select').addClass('layui-form-selected')
                getdataList();
            })
            //输入框失去焦点事件
            select_input.blur(function () {
                var input_dom = this
                $(document).on('click', function (event) {
                    var dom = select_show[0];
                    if (event.target !== input_dom && event.target !== dom) {
                        obj.find('.layui-form-select').removeClass('layui-form-selected')
                    }
                })
            })
            //当案件松开时
            select_input.keyup(function () {
                getdataList()
            })
            if (type == 'single') {
                obj.delegate('dd', 'click', function () {
                    if ($(this).index() > 0) {
                        $(this).siblings().removeClass('layui-this')
                        $(this).addClass('layui-this')
                        select_input.val($(this).text())
                        select_input.attr('id', $(this).attr('lay-value'))
                        obj.find('.layui-form-select').removeClass('layui-form-selected')
                    }
                });
            }
            // else if (type == 'select_friend') {
            //     //为选择项绑定点击事件
            //
            //     obj.delegate('dd', 'click', function () {
            //         if ($(this).index() > 0) {
            //             $(this).siblings().removeClass('layui-this')
            //             $(this).addClass('layui-this')
            //             select_input.val($(this).text())
            //             select_input.attr('id', $(this).attr('lay-value'))
            //             obj.find('.layui-form-select').removeClass('layui-form-selected')
            //         }
            //     });
            //
            //     // obj.delegate('dd', 'click', function () {
            //     //     if ($(this).index() > 0 && $(this).text() !== '无该匹配项') {
            //     //         $(this).siblings().removeClass('layui-this')
            //     //         $(this).addClass('layui-this')
            //     //         var temp = '<a class="select_a" belong_id="' + $(this).attr('lay-value') + '" ><i class="layui-icon" style="cursor: pointer;" name="select_del">ဆ</i>' + $(this).text() + '</a>'
            //     //         console.log(temp)
            //     //         select_input.prev().append(temp)
            //     //         console.log(select_input.prev())
            //     //         select_adaption(select_input)
            //     //         obj.find('.layui-form-select').removeClass('layui-form-selected')
            //     //         obj.parent().parent().next().find('input').attr('disabled', false)
            //     //         obj.parent().parent().next().find('select').attr('disabled', false)
            //     //         form.render()
            //     //     }
            //     // });
            // }
        }

        //删除选项统一接口
        $('body').delegate('[name="select_del"]', 'click', function () {
            var select_input = $(this).parent().parent().next()
            if ($(this).parent().siblings().length == 0) {
                $(this).parents(':eq(5)').nextAll().find('input').attr('disabled', true)
                $(this).parents(':eq(6)').next().find('input').attr('disabled', true)
                $(this).parents(':eq(6)').next().find('select').attr('disabled', true)
                form.render()
            }
            $(this).parent().remove()
            select_adaption(select_input)
        });

        vagueselect($('[name="single_select"]'), 'single')
        // vagueselect($('[name="single_select_friend"]'), 'select_friend')
    });
</script>






</body>
</html>